<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Returns a backtrace for each query inspected by the query cache</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.mysqlnd-qc-get-normalized-query-trace-log.html">mysqlnd_qc_get_normalized_query_trace_log</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.mysqlnd-qc-set-cache-condition.html">mysqlnd_qc_set_cache_condition</a></div>
 <div class="up"><a href="ref.mysqlnd-qc.html">mysqlnd_qc 函数</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="function.mysqlnd-qc-get-query-trace-log" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">mysqlnd_qc_get_query_trace_log</h1>
  <p class="verinfo">(PECL mysqlnd_qc &gt;= 1.0.0)</p><p class="refpurpose"><span class="refname">mysqlnd_qc_get_query_trace_log</span> &mdash; <span class="dc-title">Returns a backtrace for each query inspected by the query cache</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-function.mysqlnd-qc-get-query-trace-log-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="type">array</span> 
   <span class="methodname"><strong>mysqlnd_qc_get_query_trace_log</strong></span>
    ( <span class="methodparam">void</span>
   )</div>

  <p class="para rdfs-comment">
   Returns a backtrace for each query inspected by the query cache.
   The collection of the backtrace is disabled by default. To collect
   the backtrace you have to set the PHP configuration directive
   <em>mysqlnd_qc.collect_query_trace</em> to
   <em>1</em>
  </p>
  <p class="para">
   The maximum depth of the backtrace is limited to the depth set
   with the PHP configuration directive
   <em>mysqlnd_qc.query_trace_bt_depth</em>.
  </p>

 </div>


 <div class="refsect1 parameters" id="refsect1-function.mysqlnd-qc-get-query-trace-log-parameters">
  <h3 class="title">参数</h3>
  <p class="para">此函数没有参数。</p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.mysqlnd-qc-get-query-trace-log-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   An array of query backtrace. Every list entry contains
   the query string, a backtrace and further detail information.
  </p>

  <table class="doctable informaltable">
   
    <col width="1*" />
    <col width="9*" />
    <thead>
     <tr>
      <th>Key</th>
      <th>Description</th>
     </tr>

    </thead>

    <tbody class="tbody">
     <tr>
      <td>
       <em>query</em>
      </td>
      <td>
              Query string.
      </td>
     </tr>

     <tr>
      <td>
       <em>origin</em>
      </td>
      <td>
       Code backtrace.
      </td>
     </tr>

     <tr>
      <td>
       <em>run_time</em>
      </td>
      <td>
       Query run time in milliseconds. The collection of
       all times and the necessary
       <em>gettimeofday</em>
       system calls can be disabled by setting the PHP configuration
       directive
       <em>mysqlnd_qc.time_statistics</em> to
       <em>0</em>
      </td>
     </tr>

     <tr>
      <td>
       <em>store_time</em>
      </td>
      <td>
       Query result set store time in milliseconds. The collection of
       all times and the necessary
       <em>gettimeofday</em>
       system calls can be disabled by setting the PHP configuration
       directive
       <em>mysqlnd_qc.time_statistics</em> to
       <em>0</em>
      </td>
     </tr>

     <tr>
      <td>
       <em>eligible_for_caching</em>
      </td>
      <td>
       <strong><code>TRUE</code></strong> if query is cacheable otherwise
       <strong><code>FALSE</code></strong>.
      </td>
     </tr>

     <tr>
      <td>
       <em>no_table</em>
      </td>
      <td>
       <strong><code>TRUE</code></strong> if the query has generated a result
       set and at least one column from the result set has no table
       name set in its metadata. This is usually the case with
       queries which one probably do not want to cache such as
       <em>SELECT SLEEP(1)</em>. By default any such query
       will not be added to the cache. See also PHP configuration directive
       <em>mysqlnd_qc.cache_no_table</em>.
      </td>
     </tr>

     <tr>
      <td>
       <em>was_added</em>
      </td>
      <td>
       <strong><code>TRUE</code></strong> if the query result has been put into
       the cache, otherwise
       <strong><code>FALSE</code></strong>.
      </td>
     </tr>

     <tr>
      <td>
       <em>was_already_in_cache</em>
      </td>
      <td>
       <strong><code>TRUE</code></strong> if the query result would have been
       added to the cache if it was not already in the cache (cache hit).
       Otherwise
       <strong><code>FALSE</code></strong>.
      </td>
     </tr>


    </tbody>
   
  </table>

 </div>



 <div class="refsect1 examples" id="refsect1-function.mysqlnd-qc-get-query-trace-log-examples">
  <h3 class="title">范例</h3>
  <div class="example" id="example-1837">
   <p><strong>Example #1 <span class="function"><strong>mysqlnd_qc_get_query_trace_log()</strong></span> example</strong></p>
   <div class="example-contents">
<div class="inicode"><pre class="inicode">mysqlnd_qc.collect_query_trace=1</pre>
</div>
   </div>

   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">/*&nbsp;Connect,&nbsp;create&nbsp;and&nbsp;populate&nbsp;test&nbsp;table&nbsp;*/<br /></span><span style="color: #0000BB">$mysqli&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">mysqli</span><span style="color: #007700">(</span><span style="color: #DD0000">"host"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"user"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"password"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"schema"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"port"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"socket"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$mysqli</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">query</span><span style="color: #007700">(</span><span style="color: #DD0000">"DROP&nbsp;TABLE&nbsp;IF&nbsp;EXISTS&nbsp;test"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$mysqli</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">query</span><span style="color: #007700">(</span><span style="color: #DD0000">"CREATE&nbsp;TABLE&nbsp;test(id&nbsp;INT)"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$mysqli</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">query</span><span style="color: #007700">(</span><span style="color: #DD0000">"INSERT&nbsp;INTO&nbsp;test(id)&nbsp;VALUES&nbsp;(1),&nbsp;(2)"</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">/*&nbsp;not&nbsp;cached&nbsp;*/<br /></span><span style="color: #0000BB">$res&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$mysqli</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">query</span><span style="color: #007700">(</span><span style="color: #DD0000">"SELECT&nbsp;id&nbsp;FROM&nbsp;test&nbsp;WHERE&nbsp;id&nbsp;=&nbsp;1"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$res</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">fetch_assoc</span><span style="color: #007700">());<br /></span><span style="color: #0000BB">$res</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">free</span><span style="color: #007700">();<br /><br /></span><span style="color: #FF8000">/*&nbsp;cache&nbsp;put&nbsp;*/<br /></span><span style="color: #0000BB">$res&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$mysqli</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">query</span><span style="color: #007700">(</span><span style="color: #DD0000">"/*"&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #0000BB">MYSQLND_QC_ENABLE_SWITCH&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #DD0000">"*/"&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #DD0000">"SELECT&nbsp;id&nbsp;FROM&nbsp;test&nbsp;WHERE&nbsp;id&nbsp;=&nbsp;2"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$res</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">fetch_assoc</span><span style="color: #007700">());<br /></span><span style="color: #0000BB">$res</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">free</span><span style="color: #007700">();<br /><br /></span><span style="color: #FF8000">/*&nbsp;cache&nbsp;hit&nbsp;*/<br /></span><span style="color: #0000BB">$res&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$mysqli</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">query</span><span style="color: #007700">(</span><span style="color: #DD0000">"/*"&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #0000BB">MYSQLND_QC_ENABLE_SWITCH&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #DD0000">"*/"&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #DD0000">"SELECT&nbsp;id&nbsp;FROM&nbsp;test&nbsp;WHERE&nbsp;id&nbsp;=&nbsp;2"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$res</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">fetch_assoc</span><span style="color: #007700">());<br /></span><span style="color: #0000BB">$res</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">free</span><span style="color: #007700">();<br /><br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">mysqlnd_qc_get_query_trace_log</span><span style="color: #007700">());<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
   </div>

   <div class="example-contents"><p>以上例程会输出：</p></div>
   <div class="example-contents screen">
<div class="cdata"><pre>
array(1) {
  [&quot;id&quot;]=&gt;
  string(1) &quot;1&quot;
}
array(1) {
  [&quot;id&quot;]=&gt;
  string(1) &quot;2&quot;
}
array(1) {
  [&quot;id&quot;]=&gt;
  string(1) &quot;2&quot;
}
array(6) {
  [0]=&gt;
  array(8) {
    [&quot;query&quot;]=&gt;
    string(25) &quot;DROP TABLE IF EXISTS test&quot;
    [&quot;origin&quot;]=&gt;
    string(102) &quot;#0 qc.php(4): mysqli-&gt;query(&#039;DROP TABLE IF E...&#039;)
#1 {main}&quot;
    [&quot;run_time&quot;]=&gt;
    int(0)
    [&quot;store_time&quot;]=&gt;
    int(0)
    [&quot;eligible_for_caching&quot;]=&gt;
    bool(false)
    [&quot;no_table&quot;]=&gt;
    bool(false)
    [&quot;was_added&quot;]=&gt;
    bool(false)
    [&quot;was_already_in_cache&quot;]=&gt;
    bool(false)
  }
  [1]=&gt;
  array(8) {
    [&quot;query&quot;]=&gt;
    string(25) &quot;CREATE TABLE test(id INT)&quot;
    [&quot;origin&quot;]=&gt;
    string(102) &quot;#0 qc.php(5): mysqli-&gt;query(&#039;CREATE TABLE te...&#039;)
#1 {main}&quot;
    [&quot;run_time&quot;]=&gt;
    int(0)
    [&quot;store_time&quot;]=&gt;
    int(0)
    [&quot;eligible_for_caching&quot;]=&gt;
    bool(false)
    [&quot;no_table&quot;]=&gt;
    bool(false)
    [&quot;was_added&quot;]=&gt;
    bool(false)
    [&quot;was_already_in_cache&quot;]=&gt;
    bool(false)
  }
  [2]=&gt;
  array(8) {
    [&quot;query&quot;]=&gt;
    string(36) &quot;INSERT INTO test(id) VALUES (1), (2)&quot;
    [&quot;origin&quot;]=&gt;
    string(102) &quot;#0 qc.php(6): mysqli-&gt;query(&#039;INSERT INTO tes...&#039;)
#1 {main}&quot;
    [&quot;run_time&quot;]=&gt;
    int(0)
    [&quot;store_time&quot;]=&gt;
    int(0)
    [&quot;eligible_for_caching&quot;]=&gt;
    bool(false)
    [&quot;no_table&quot;]=&gt;
    bool(false)
    [&quot;was_added&quot;]=&gt;
    bool(false)
    [&quot;was_already_in_cache&quot;]=&gt;
    bool(false)
  }
  [3]=&gt;
  array(8) {
    [&quot;query&quot;]=&gt;
    string(32) &quot;SELECT id FROM test WHERE id = 1&quot;
    [&quot;origin&quot;]=&gt;
    string(102) &quot;#0 qc.php(9): mysqli-&gt;query(&#039;SELECT id FROM ...&#039;)
#1 {main}&quot;
    [&quot;run_time&quot;]=&gt;
    int(0)
    [&quot;store_time&quot;]=&gt;
    int(25)
    [&quot;eligible_for_caching&quot;]=&gt;
    bool(false)
    [&quot;no_table&quot;]=&gt;
    bool(false)
    [&quot;was_added&quot;]=&gt;
    bool(false)
    [&quot;was_already_in_cache&quot;]=&gt;
    bool(false)
  }
  [4]=&gt;
  array(8) {
    [&quot;query&quot;]=&gt;
    string(41) &quot;/*qc=on*/SELECT id FROM test WHERE id = 2&quot;
    [&quot;origin&quot;]=&gt;
    string(103) &quot;#0 qc.php(14): mysqli-&gt;query(&#039;/*qc=on*/SELECT...&#039;)
#1 {main}&quot;
    [&quot;run_time&quot;]=&gt;
    int(311)
    [&quot;store_time&quot;]=&gt;
    int(13)
    [&quot;eligible_for_caching&quot;]=&gt;
    bool(true)
    [&quot;no_table&quot;]=&gt;
    bool(false)
    [&quot;was_added&quot;]=&gt;
    bool(true)
    [&quot;was_already_in_cache&quot;]=&gt;
    bool(false)
  }
  [5]=&gt;
  array(8) {
    [&quot;query&quot;]=&gt;
    string(41) &quot;/*qc=on*/SELECT id FROM test WHERE id = 2&quot;
    [&quot;origin&quot;]=&gt;
    string(103) &quot;#0 qc.php(19): mysqli-&gt;query(&#039;/*qc=on*/SELECT...&#039;)
#1 {main}&quot;
    [&quot;run_time&quot;]=&gt;
    int(13)
    [&quot;store_time&quot;]=&gt;
    int(8)
    [&quot;eligible_for_caching&quot;]=&gt;
    bool(true)
    [&quot;no_table&quot;]=&gt;
    bool(false)
    [&quot;was_added&quot;]=&gt;
    bool(false)
    [&quot;was_already_in_cache&quot;]=&gt;
    bool(true)
  }
}
</pre></div>
   </div>

  </div>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.mysqlnd-qc-get-query-trace-log-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member">
     <a href="mysqlnd-qc.configuration.html" class="link">Runtime configuration</a>
    </li>
    <li class="member">
     <a href="mysqlnd-qc.configuration.html#ini.mysqlnd-qc.collect-query-trace" class="link">mysqlnd_qc.collect_query_trace</a>
    </li>
    <li class="member">
     <a href="mysqlnd-qc.configuration.html#ini.mysqlnd-qc.query-trace-bt-depth" class="link">mysqlnd_qc.query_trace_bt_depth</a>
    </li>
    <li class="member">
     <a href="mysqlnd-qc.configuration.html#ini.mysqlnd-qc.time-statistics" class="link">mysqlnd_qc.time_statistics</a>
    </li>
    <li class="member">
     <a href="mysqlnd-qc.configuration.html#ini.mysqlnd-qc.cache-no-table" class="link">mysqlnd_qc.cache_no_table</a>
    </li>
    <li class="member">
     <span class="function"><a href="function.mysqlnd-qc-get-normalized-query-trace-log.html" class="function" rel="rdfs-seeAlso">mysqlnd_qc_get_normalized_query_trace_log()</a> - Returns a normalized query trace log for each query inspected by the query cache</span>
    </li>
   </ul>
  </p>
 </div>


</div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.mysqlnd-qc-get-normalized-query-trace-log.html">mysqlnd_qc_get_normalized_query_trace_log</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.mysqlnd-qc-set-cache-condition.html">mysqlnd_qc_set_cache_condition</a></div>
 <div class="up"><a href="ref.mysqlnd-qc.html">mysqlnd_qc 函数</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>
